// 自动锁定高亮菜单栏
function checkSelectMenu(name) {
    $(".selectMenu").each(function (i, item) {
        if ($(this).prop('id') !== name) {
            $(this).removeClass("active");
        } else {
            $(this).addClass("active");
        }
    });
}

//创建时间格式化显示
function crtTimeFtt(value) {
    if (null == value || value === '') {
        return "";
    }
    /*value = parseInt(value);
     var date = new Date(value);
     return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();*/
    var date = new Date(parseInt(value));

    var year = date.getFullYear(),
        month = date.getMonth() + 1,//月份是从0开始的
        day = date.getDate(),
        hour = date.getHours(),
        min = date.getMinutes(),
        sec = date.getSeconds();
    return year + '-' +
        (month < 10 ? '0' + month : month) + '-' +
        (day < 10 ? '0' + day : day) + ' ' +
        (hour < 10 ? '0' + hour : hour) + ':' +
        (min < 10 ? '0' + min : min) + ':' +
        (sec < 10 ? '0' + sec : sec);
}

function getTime() {
    var date = new Date();

    var year = date.getFullYear(),
        month = date.getMonth() + 1,//月份是从0开始的
        day = date.getDate(),
        hour = date.getHours(),
        min = date.getMinutes(),
        sec = date.getSeconds();
    return year + '-' +
        (month < 10 ? '0' + month : month) + '-' +
        (day < 10 ? '0' + day : day) + ' ' +
        (hour < 10 ? '0' + hour : hour) + ':' +
        (min < 10 ? '0' + min : min) + ':' +
        (sec < 10 ? '0' + sec : sec);
}

function info(status, msg) {
    bootoast({
        message: msg,
        type: status,
        position: 'right-bottom',
        timeout: 2
    });


}

/*校验手机号*/


function getTest() {
    var obj = {
        notnull: 0,
        phone: 1,//电话常量
        password: 2,
        number: 3
    };
    obj.test = function (text, type) {
        if (text === "" || null == text) {
            return false;
        }
        switch (type) {
            case 0:
                return !(text === "" || null == text);
            case 1:
                var isPhone = /^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
                var isMob = /^1[34578]\d{9}$/;
                return isMob.test(text) || isPhone.test(text);
            case 2:
                if (text.length < 8) {
                    return false;
                } else {
                    var reg1 = new RegExp(/^[0-9A-Za-z]+$/);
                    return reg1.test(text);

                }
            case 3:
                var regPos = /^\d+(\.\d+)?$/; //非负浮点数
                var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
                return regPos.test(text) || regNeg.test(text);
            default:
                return;
        }
    };
    return obj;
}

function checkNumber(val) {
    if (parseFloat(val).toString() === "NaN") {
        return false;
    }
    var regPos = /^[1-9]+[0-9]*]*$/;
    return regPos.test(val);
}

function checkMoney(val) {
    if (null == val || val === '') {
        return false;
    }

    var vs = val.split(".");
    if (vs.length > 2 || vs.length < 1) {
        return false;
    }

    var flag = 0;
    for (var i = 0; i < vs.length; i++) {
        if (!checkNumber(vs[i])) {
            flag = 1;
        }
    }

    return flag === 0;
}

function checkAccount(str) {
    var re = /^[a-zA-Z][a-zA-Z0-9]{0,19}$/;
    return re.test(str);
}

function checkMobile(str) {
    var re = /^1(3|4|5|7|8)\d{9}$/;
    return re.test(str);
}

function checkEmail(str) {
    var re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
    return re.test(str);
}

function checkUrl(str_url) {
    var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
        + "?(([0-9a-zA-Z_!~*'().&=+$%-]+: )?[0-9a-zA-Z_!~*'().&=+$%-]+@)?" //ftp的user@
        + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
        + "|" // 允许IP和DOMAIN（域名）
        + "([0-9a-zA-Z_!~*'()-]+\.)*" // 域名- www.
        + "([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\." // 二级域名
        + "[a-zA-Z]{2,6})" // first level domain- .com or .museum
        + "(:[0-9]{1,4})?" // 端口- :80
        + "((/?)|"
        + "(/[0-9a-zA-Z_!~*'().;?:@&=+$,%#-]+)+/?)$";
    var re = new RegExp(strRegex);
    return re.test(str_url);
}

/*设置字体颜色*/
function greatColor(number, type) {
    switch (type) {
        case 0:
            return "<span style='color:green'>+" + number + "</span>";
        case 1:
            return "<span style='color:red'>" + number + "</span>";
        case 2:
            return "<span style='color:blue'>" + number + "</span>";
    }
}


/*模糊查询下拉框*/
var TempArr = [];//存储option
$(function () {
    /*先将数据存入数组*/
    $("#typenum option").each(function (index, el) {
        TempArr[index] = $(this).text();
    });
    $(document).bind('click', function (e) {
        var e = e || window.event; //浏览器兼容性
        var elem = e.target || e.srcElement;
        while (elem) { //循环判断至跟节点，防止点击的是div子元素
            if (elem.id && (elem.id == 'typenum' || elem.id == "makeupCo")) {
                return;
            }
            elem = elem.parentNode;
        }
        $('#typenum').css('display', 'none'); //点击的不是div或其子元素
    });
})

function changeF(this_) {
    $(this_).prev("input").val($(this_).find("option:selected").text());
    $("#typenum").css({"display": "none"});
}

function setfocus(this_) {
    $("#typenum").css({"display": ""});
    var select = $("#typenum");
    for (i = 0; i < TempArr.length; i++) {
        var option = $("<option></option>").text(TempArr[i]);
        select.append(option);
    }
    setinput(this_);
}

function setinput(this_) {
    var select = $("#typenum");
    select.html("");
    for (i = 0; i < TempArr.length; i++) {
        //若找到以txt的内容开头的，添option
        if (TempArr[i].substring(0, this_.value.length).indexOf(this_.value) == 0) {
            var option = $("<option></option>").text(TempArr[i]);
            select.append(option);
        }
    }
}

/*获取货物类别*/
function getType(type) {
    if (type == 0) {
        return "集装箱";

    } else if (type == 1) {
        return "散装";
    } else {
        return "未知类型";
    }
}

function getMoney(data, type) {
    switch (Number(type)) {
        case 4:
            if (data.type === 0) {
                return "" + data.transportMoney + " (元/箱)"
            } else if (data.type === 1) {
                return "" + data.transportMoney + " (元/吨)"
            }
            break;
        case 5:
            if (data.type === 0) {
                return "" + data.dockMoney + " (元/箱)"
            } else if (data.type === 1) {
                return "" + data.dockMoney + " (元/吨)"
            }
            break;
        case 6:
            if (data.type === 0) {
                return "" + data.money + " (元/箱)"
            } else if (data.type === 1) {
                return "" + data.money + " (元/吨)"
            }
            break;
        case 7:
            if (data.type === 0) {
                return "" + data.settleMoney + " (元/箱)"
            } else if (data.type === 1) {
                return "" + data.settleMoney + " (元/吨)"
            }
            break;
    }
}

/*字符串专换成a标签*/
function textToA(data) {
    if (data.num != "" && data.num != null && data.id != null && data.id !== "") {
        return "<a href='./backend/order/editWaybill?id=" + data.id + "'>" + data.num + "</a>";

    }
    return "运单没有找到";
}


function check_0_yes(b) {
    if (b)
        return 0;
    return 1;
}

function check_0_no(b) {
    if (b)
        return 1;
    return 0;
}

//代码如下所示：
function convertCurrency(money) {
    //汉字的数字
    var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
    //基本单位
    var cnIntRadice = new Array('', '拾', '佰', '仟');
    //对应整数部分扩展单位
    var cnIntUnits = new Array('', '万', '亿', '兆');
    //对应小数部分单位
    var cnDecUnits = new Array('角', '分', '毫', '厘');
    //整数金额时后面跟的字符
    var cnInteger = '整';
    //整型完以后的单位
    var cnIntLast = '元';
    //最大处理的数字
    var maxNum = 999999999999999.9999;
    //金额整数部分
    var integerNum;
    //金额小数部分
    var decimalNum;
    //输出的中文金额字符串
    var chineseStr = '';
    //分离金额后用的数组，预定义
    var parts;
    if (money == '') {
        return '';
    }
    money = parseFloat(money);
    if (money >= maxNum) {
        //超出最大处理数字
        return '';
    }
    if (money == 0) {
        chineseStr = cnNums[0] + cnIntLast + cnInteger;
        return chineseStr;
    }
    //转换为字符串
    money = money.toString();
    if (money.indexOf('.') == -1) {
        integerNum = money;
        decimalNum = '';
    } else {
        parts = money.split('.');
        integerNum = parts[0];
        decimalNum = parts[1].substr(0, 4);
    }
    //获取整型部分转换
    if (parseInt(integerNum, 10) > 0) {
        var zeroCount = 0;
        var IntLen = integerNum.length;
        for (var i = 0; i < IntLen; i++) {
            var n = integerNum.substr(i, 1);
            var p = IntLen - i - 1;
            var q = p / 4;
            var m = p % 4;
            if (n == '0') {
                zeroCount++;
            } else {
                if (zeroCount > 0) {
                    chineseStr += cnNums[0];
                }
                //归零
                zeroCount = 0;
                chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
            }
            if (m == 0 && zeroCount < 4) {
                chineseStr += cnIntUnits[q];
            }
        }
        chineseStr += cnIntLast;
    }
    //小数部分
    if (decimalNum != '') {
        var decLen = decimalNum.length;
        for (var i = 0; i < decLen; i++) {
            var n = decimalNum.substr(i, 1);
            if (n != '0') {
                chineseStr += cnNums[Number(n)] + cnDecUnits[i];
            }
        }
    }
    if (chineseStr == '') {
        chineseStr += cnNums[0] + cnIntLast + cnInteger;
    } else if (decimalNum == '') {
        chineseStr += cnInteger;
    }
    return chineseStr;
}

//创建时间格式化显示中文
function crtTimeFtt_zw(value) {
    if (null == value || value == '') {
        return "";
    }
    /*value = parseInt(value);
     var date = new Date(value);
     return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();*/
    var date = new Date(parseInt(value));

    var year = date.getFullYear(),
        month = date.getMonth() + 1,//月份是从0开始的
        day = date.getDate(),
        hour = date.getHours(),
        min = date.getMinutes(),
        sec = date.getSeconds();
    return year + '年' +
        (month < 10 ? '0' + month : month) + '月' +
        (day < 10 ? '0' + day : day) + ' 日'
}